package org.cug.service.impl;

import org.cug.mapper.GraduateTeachingMapper;
import org.cug.mapper.UserMapper;
import org.cug.pojo.GraduateTeaching;
import org.cug.pojo.User;
import org.cug.service.GraduateTeachingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class GraduateTeachingServiceimpl implements GraduateTeachingService {
    @Autowired
    private GraduateTeachingMapper graduateTeachingMapper;
    @Autowired
    private UserMapper userMapper;
    @Override
    public List<GraduateTeaching> list(Integer userId, Short semester) {
        User user =userMapper.getrole(userId);
        List<Integer> ids=new ArrayList<>();
        if(user.getRole().equals("1")){
            ids.add(userId);
        }
        else if(user.getRole().equals("2")){
            ids = userMapper.getusers(user.getDepartment());
        }else if(user.getRole().equals("3")){
            ids = userMapper.getuserscol(user.getCollege());
        }else {
            List<GraduateTeaching> graduateTeachings = graduateTeachingMapper.listall(semester);
            return graduateTeachings;
        }
        List<GraduateTeaching> graduateTeachings = graduateTeachingMapper.list(ids,semester);
        return graduateTeachings;
    }

    @Override
    public void add(GraduateTeaching graduateTeaching) {
        graduateTeachingMapper.insert(graduateTeaching);
    }

    @Override
    public void delete(List<Integer> ids) {
        graduateTeachingMapper.delete(ids);
    }

    @Override
    public GraduateTeaching selectid(Integer id) {
        return graduateTeachingMapper.selectid(id);
    }

    @Override
    public void alterbyid(GraduateTeaching graduateTeaching) {
        graduateTeachingMapper.update(graduateTeaching);
    }
}
